package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.common.entity.ChatMessage;
import com.woniuxy.entity.AllUser;
import com.woniuxy.entity.DTO.FindUserIdByConversationDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;


import java.util.List;

@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
    // 查找两个用户之间的未读消息
    List<ChatMessage> findBySenderIdAndReceiverIdAndStatus(
            @Param("senderId") String senderId,
            @Param("receiverId") String receiverId,
            @Param("status") ChatMessage.MessageStatus status);

    // 查找用户的所有未读消息
    List<ChatMessage> findByReceiverIdAndStatus(
            @Param("receiverId") String receiverId,
            @Param("userId") String userId,
            @Param("status") ChatMessage.MessageStatus status);

    // 更新消息为已送达
    int markMessagesAsDelivered(@Param("userId") String userId,@Param("receiverId") String receiverId);

    // 分页查询对话历史
    List<ChatMessage> findConversation(
            @Param("user1") String user1,
            @Param("user2") String user2);
//查询哪些人和当前账户聊过天返回userId和最后一次聊天的时间
    List<FindUserIdByConversationDTO> findUserIdByConversation(@Param("userId") String userId);
//查询查询最后一条消息
    String findLastMessage(@Param("receiverId") String receiverId,@Param("senderId") String senderId);
    //查询查询最后一条消息对象
    ChatMessage findLastMessageObject(@Param("receiverId") String receiverId,@Param("senderId") String senderId);
//    查询未读的消息条数
    Integer findUnreadCount(@Param("receiverId") String receiverId,@Param("senderId") String senderId);
    //    查询已读的消息条数
    Integer findReadCount(@Param("receiverId") String receiverId,@Param("senderId") String senderId);
    //通过id查询user信息
    AllUser findUserById(@Param("userId") Long userId);
    // 查找用户的所有消息，包含已读和未读的
    List<ChatMessage> findByAllChatMessage(
            @Param("receiverId") String receiverId,
            @Param("userId") String userId);

}
